<template>
  <div v-if="reviewType === '1'">
    <t-card size="small" style="margin-bottom: 10px" title="立项专家评审意见">
      <!--      <div v-if="reviewGroupRecord?.content" class="query-form-inline">-->
      <!--        <h3>：{{reviewGroupRecord?.content}}</h3>-->
      <!--      </div>-->
      <t-alert style="margin-bottom: 10px" theme="info" v-if="reviewGroupRecord?.content"
        :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`" :message="reviewGroupRecord?.content">
      </t-alert>
      <t-alert v-else theme="info" style="margin-bottom: 10px" :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`"
        message="未提交">
      </t-alert>
      <t-table size="small" rowKey="id" :data="data" :columns="columns2" hover>
        <template #sysAttMainEntities="{ row }">
          <a class="t-button-link" v-for="(item, index) in row.sysAttMainEntities" :key="index" target="_blank"
            :href="item.fullFilePath">
            {{ item.fileName }}
          </a>
        </template>
        <template #reviewStatus="{ row }">
          <t-tag theme="success" variant="light" v-if="row.reviewStatus === '1'">
            已提交
          </t-tag>
          <t-tag v-else-if="row.reviewStatus === '0'" theme="warning" variant="light">暂存</t-tag>
          <t-tag theme="danger" variant="light" v-else>
            未提交
          </t-tag>
        </template>
        <template #id="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
        <template #recommendType="{ row }">
          <t-tag theme="danger" variant="light" v-if="row.recommendType === '1'">
            {{ row.recommendType | filterByDict(dict.type.recommend_type) }}
          </t-tag>
          <t-tag theme="success" variant="light" v-else-if="row.recommendType === '2'">
            {{ row.recommendType | filterByDict(dict.type.recommend_type) }}
          </t-tag>
          <t-tag theme="success" variant="light" v-else-if="row.recommendType === '3'">
            {{ row.recommendType | filterByDict(dict.type.recommend_type) }}
          </t-tag>
          <t-tag theme="warning" v-else variant="light">
            未提交
          </t-tag>
        </template>
      </t-table>
    </t-card>
    <t-card v-if="data2.length > 0" size="small" title="大纲专家评审意见(复议)">
      <!--      <div v-if="reviewGroupRecord2?.content" class="query-form-inline">-->
      <!--        <h3>{{site_tag==='jtt'?'科教处':'科信部'}}意见：{{reviewGroupRecord2?.content}}</h3>-->
      <!--      </div>-->
      <!--      <div  class="query-form-inline">-->
      <!--        <h3>专家组评审意见表：<a v-if="psYjsFilesNow2.length>0" class="t-button-link" target="_blank"  :href="psYjsFilesNow2[0].url" >-->
      <!--          {{psYjsFilesNow2[0].name}}-->
      <!--        </a><span v-else>未提交</span></h3>-->
      <!--      </div>-->
      <t-alert style="margin-bottom: 10px" theme="info" v-if="reviewGroupRecord2?.content"
        :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`" :message="reviewGroupRecord2?.content">
      </t-alert>
      <t-alert v-else theme="info" style="margin-bottom: 10px" :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`"
        message="未提交">
      </t-alert>
      <t-alert style="margin-bottom: 10px" theme="info" v-if="psYjsFilesNow2.length > 0" title="专家组评审意见表">
        <template #message>
          <a class="t-button-link" target="_blank" :href="psYjsFilesNow2[0].url">
            {{ psYjsFilesNow2[0].name }}
          </a>
        </template>
      </t-alert>
      <t-alert v-else theme="info" style="margin-bottom: 10px" title="专家组评审意见表" message="未提交">
      </t-alert>
      <t-table size="small" rowKey="id" :data="data2" :columns="columns3" hover>
        <template #sysAttMainEntities="{ row }">
          <a class="t-button-link" v-for="(item, index) in row.sysAttMainEntities" :key="index" target="_blank"
            :href="item.fullFilePath">
            {{ item.fileName }}
          </a>
        </template>
        <template #id="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
        <template #reviewStatus="{ row }">
          <t-tag theme="success" variant="light" v-if="row.reviewStatus === '1'">
            已提交
          </t-tag>
          <t-tag v-else-if="row.reviewStatus === '0'" theme="warning" variant="light">暂存</t-tag>
          <t-tag theme="danger" variant="light" v-else>
            未提交
          </t-tag>
        </template>
        <template #projectApproval="{ row }">
          <!--          <t-tag theme="success" variant="light" v-if="row.projectApproval==='1'">-->
          <!--            是-->
          <!--          </t-tag>-->
          <!--          <t-tag theme="danger" variant="light" v-else-if="row.projectApproval==='0'">-->
          <!--            否-->
          <!--          </t-tag>-->
          <!--          <t-tag theme="warning" variant="light" v-else-if="row.projectApproval==='2'">-->
          <!--            需要复议-->
          <!--          </t-tag>-->
          <!--          <t-tag theme="warning" variant="light" v-else>-->
          <!--            未提交-->
          <!--          </t-tag>-->
          <t-tag v-if="row.projectApproval" :theme="handleTheme(row.projectApproval, dict.type.kjxm_lx_review_status)"
            variant="light">
            {{ row.projectApproval | filterByDict(dict.type.kjxm_lx_review_status) }}
          </t-tag>
          <t-tag v-else theme="warning" variant="light">未提交
          </t-tag>
        </template>
      </t-table>
    </t-card>
  </div>
  <div v-else-if="reviewType === '2'">
    <t-card size="small" title="大纲专家评审意见">
      <!--      <div v-if="reviewGroupRecord?.content" class="query-form-inline">-->
      <!--        <h3>{{site_tag==='jtt'?'科教处':'科信部'}}意见：{{reviewGroupRecord?.content}}</h3>-->
      <!--      </div>-->
      <!--      <div  class="query-form-inline">-->
      <!--        <h3>专家组评审意见表：<a v-if="psYjsFilesNow.length>0" class="t-button-link" target="_blank"  :href="psYjsFilesNow[0].url" >-->
      <!--          {{psYjsFilesNow[0].name}}-->
      <!--        </a><span v-else>未提交</span></h3>-->
      <!--      </div>-->
      <t-alert style="margin-bottom: 10px" theme="info" v-if="reviewGroupRecord?.content"
        :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`" :message="reviewGroupRecord?.content">
      </t-alert>
      <t-alert v-else theme="info" style="margin-bottom: 10px" :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`"
        message="未提交">
      </t-alert>
      <t-alert style="margin-bottom: 10px" theme="info" v-if="psYjsFilesNow.length > 0" title="专家组评审意见表">
        <template #message>
          <a class="t-button-link" target="_blank" :href="psYjsFilesNow[0].url">
            {{ psYjsFilesNow[0].name }}
          </a>
        </template>
      </t-alert>
      <t-alert v-else theme="info" style="margin-bottom: 10px" title="专家组评审意见表" message="未提交">
      </t-alert>

      <t-table size="small" rowKey="id" :data="data" :columns="columns3" hover>
        <template #sysAttMainEntities="{ row }">
          <a class="t-button-link" v-for="(item, index) in row.sysAttMainEntities" :key="index" target="_blank"
            :href="item.fullFilePath">
            {{ item.fileName }}
          </a>
        </template>
        <template #id="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
        <template #reviewStatus="{ row }">
          <t-tag theme="success" variant="light" v-if="row.reviewStatus === '1'">
            已提交
          </t-tag>
          <t-tag v-else-if="row.reviewStatus === '0'" theme="warning" variant="light">暂存</t-tag>
          <t-tag theme="danger" variant="light" v-else>
            未提交
          </t-tag>
        </template>
        <template #projectApproval="{ row }">
          <!--          <t-tag theme="success" variant="light" v-if="row.projectApproval==='1'">-->
          <!--            是-->
          <!--          </t-tag>-->
          <!--          <t-tag theme="danger" variant="light" v-else-if="row.projectApproval==='0'">-->
          <!--            否-->
          <!--          </t-tag>-->
          <!--          <t-tag theme="warning" variant="light" v-else-if="row.projectApproval==='2'">-->
          <!--            需要复议-->
          <!--          </t-tag>-->
          <!--          <t-tag theme="warning" variant="light" v-else>-->
          <!--            未提交-->
          <!--          </t-tag>-->
          <t-tag v-if="row.projectApproval" :theme="handleTheme(row.projectApproval, dict.type.kjxm_review_status)"
            variant="light">
            {{ row.projectApproval | filterByDict(dict.type.kjxm_review_status) }}
          </t-tag>
          <t-tag v-else theme="warning" variant="light">未提交
          </t-tag>
        </template>
      </t-table>
    </t-card>
  </div>
  <div v-else-if="reviewType === '3'">
    <t-card size="small" title="验收专家评审意见">
      <!--      <div v-if="reviewGroupRecord?.content" class="query-form-inline">-->
      <!--        <h3>{{site_tag==='jtt'?'科教处':'科信部'}}意见：{{reviewGroupRecord?.content}}</h3>-->
      <!--      </div>-->
      <!--      <div  class="query-form-inline">-->
      <!--        <h3>专家组评审意见表：<a v-if="psYjsFilesNow.length>0" class="t-button-link" target="_blank"  :href="psYjsFilesNow[0].url" >-->
      <!--          {{psYjsFilesNow[0].name}}-->
      <!--        </a><span v-else>未提交</span></h3>-->
      <!--      </div>-->
      <t-alert style="margin-bottom: 10px" theme="info" v-if="reviewGroupRecord?.content"
        :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`" :message="reviewGroupRecord?.content">
      </t-alert>
      <t-alert v-else theme="info" style="margin-bottom: 10px" :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`"
        message="未提交">
      </t-alert>
      <t-alert style="margin-bottom: 10px" theme="info" v-if="psYjsFilesNow.length > 0" title="专家组评审意见表">
        <template #message>
          <a class="t-button-link" target="_blank" :href="psYjsFilesNow[0].url">
            {{ psYjsFilesNow[0].name }}
          </a>
        </template>
      </t-alert>
      <t-alert v-else theme="info" style="margin-bottom: 10px" title="专家组评审意见表" message="未提交">
      </t-alert>
      <t-table size="small" rowKey="id" :data="data" :columns="columns3" hover>
        <template #sysAttMainEntities="{ row }">
          <a class="t-button-link" v-for="(item, index) in row.sysAttMainEntities" :key="index" target="_blank"
            :href="item.fullFilePath">
            {{ item.fileName }}
          </a>
        </template>
        <template #id="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
        <template #reviewStatus="{ row }">
          <t-tag theme="success" variant="light" v-if="row.reviewStatus === '1'">
            已提交
          </t-tag>
          <t-tag v-else-if="row.reviewStatus === '0'" theme="warning" variant="light">暂存</t-tag>
          <t-tag theme="danger" variant="light" v-else>
            未提交
          </t-tag>
        </template>


        <template #projectApproval="{ row }">
          <!--          <t-tag theme="success" variant="light" v-if="row.projectApproval==='1'">-->
          <!--            是-->
          <!--          </t-tag>-->
          <!--          <t-tag theme="danger" variant="light" v-else-if="row.projectApproval==='0'">-->
          <!--            否-->
          <!--          </t-tag>-->
          <!--          <t-tag theme="warning" variant="light" v-else-if="row.projectApproval==='2'">-->
          <!--            需要复议-->
          <!--          </t-tag>-->
          <!--          <t-tag theme="warning" variant="light" v-else>-->
          <!--            未提交-->
          <!--          </t-tag>-->
          <t-tag v-if="row.projectApproval" :theme="handleTheme(row.projectApproval, dict.type.kjxm_review_status)"
            variant="light">
            {{ row.projectApproval | filterByDict(dict.type.kjxm_review_status) }}
          </t-tag>
          <t-tag v-else theme="warning" variant="light">未提交
          </t-tag>
        </template>
      </t-table>
    </t-card>
  </div>
  <div v-else-if="['4', '5'].includes(reviewType)">
    <t-card size="small" :title="reviewType === '4' ? '第一次立项评审意见' : '第二次立项评审意见'">
      <t-alert style="margin-bottom: 10px" theme="info" v-if="reviewGroupRecord?.content"
        :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`" :message="reviewGroupRecord?.content">
      </t-alert>
      <t-alert v-else theme="info" style="margin-bottom: 10px" :title="`${site_tag === 'jtt' ? '科教处' : '科信部'}意见`"
        message="未提交">
      </t-alert>
      <t-alert style="margin-bottom: 10px" theme="info" v-if="psYjsFilesNow.length > 0" title="专家组评审意见表">
        <template #message>
          <a class="t-button-link" target="_blank" :href="psYjsFilesNow[0].url">
            {{ psYjsFilesNow[0].name }}
          </a>
        </template>
      </t-alert>
      <t-alert v-else theme="info" style="margin-bottom: 10px" title="专家组评审意见表" message="未提交">
      </t-alert>
      <t-table size="small" rowKey="id" :data="data" :columns="columns3" hover>
        <template #sysAttMainEntities="{ row }">
          <a class="t-button-link" v-for="(item, index) in row.sysAttMainEntities" :key="index" target="_blank"
            :href="item.fullFilePath">
            {{ item.fileName }}
          </a>
        </template>
        <template #id="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
        <template #reviewStatus="{ row }">
          <t-tag theme="success" variant="light" v-if="row.reviewStatus === '1'">
            已提交
          </t-tag>
          <t-tag v-else-if="row.reviewStatus === '0'" theme="warning" variant="light">暂存</t-tag>
          <t-tag theme="danger" variant="light" v-else>
            未提交
          </t-tag>
        </template>


        <template #projectApproval="{ row }">
          <t-tag v-if="row.projectApproval" :theme="handleTheme(row.projectApproval, dict.type.kjxm_ys_review_status)"
            variant="light">
            {{ row.projectApproval | filterByDict(dict.type.kjxm_ys_review_status) }}
          </t-tag>
          <t-tag v-else theme="warning" variant="light">未提交
          </t-tag>
        </template>
      </t-table>
    </t-card>
  </div>
</template>

<script>
import { getFiles } from "@/api/common";

export default {
  name: "approve-list-by-review-type",
  dicts: ['approve_type', "subject_classification", "prof_tit", "duty", "recommend_type", "kjxm_ys_review_status", "kjxm_review_status", "kjxm_lx_review_status"],
  props: {
    reviewType: {
      type: String
    },
    objId: [String, Number],
  },
  data () {
    return {
      site_tag: import.meta.env.VITE_SITE_TAG,
      data: [],
      columns2: [
        {
          colKey: "id",
          title: "专家序号",
          align: "center",
          width: 100,
        },
        { colKey: 'reviewStatus', title: '评审状态', align: "center", width: 100 },
        { colKey: 'score', title: '评审分数', align: "center", width: 100 },
        { colKey: 'content', title: '评审意见', align: "center", width: 300 },
        { colKey: 'sysAttMainEntities', title: '评审附件', align: "center", width: 120 },
        // {colKey: 'projectApproval', title: '是否通过',align: "center"},
        { colKey: 'recommendType', title: '是否推荐', align: "center", width: 100 },
      ],
      columns3: [
        {
          colKey: "id",
          title: "专家序号",
          align: "center",
          width: 100,
        },

        { colKey: 'reviewStatus', title: '评审状态', align: "center", width: 100 },
        { colKey: 'content', title: '评审意见', align: "center", width: 300 },
        { colKey: 'sysAttMainEntities', title: '评审附件', align: "center", width: 120 },
        // {colKey: 'score', title: '评审分数',align: "center"},
        { colKey: 'projectApproval', title: '是否通过', align: "center", width: 100 },

      ],
      reviewGroupRecord: null,
      psYjsFilesNow: [],
      reviewGroupRecord2: null,
      data2: [],
      psYjsFilesNow2: [],
    }
  },
  created () {
    this.getReviewList();
    this.getKjcReply();
    // 获取当前阶段
    // this.getReviewList2();
    this.getKjcReply2();
  },
  methods: {
    getKjcReply () {
      this.$api.kjxm.review.projectReviewTeamGetByBusinessIdAndReviewType({
        businessId: this.objId,
        reviewType: this.reviewType,
      }).then(res => {
        this.reviewGroupRecord = res.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getKjcReply2 () {
      this.$api.kjxm.review.projectReviewTeamGetByBusinessIdAndReviewType({
        businessId: this.objId,
        reviewType: Number(this.reviewType) + 1,
      }).then(res => {
        this.reviewGroupRecord2 = res.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getReviewList () {
      console.log('--------------');

      this.$api.kjxm.review.projectExpertsInfoByReviewType({
        projectId: this.objId,
        // reviewType: this.reviewType,
        reviewType: 1,
      }).then(response => {
        this.data = response.data || [];
        this.psYjsFilesNow = [];
        // if(this.data.length>0){
        //   this.$api.kjxm.review.getByTeamIdAndBusinessId(this.objId,this.data[0].teamId).then(res => {
        //     getFiles(res.data.id).then((res) => {
        //       const files = {}
        //       res.data.forEach((item) => {
        //         if (!files[item.moduleKey]) {
        //           files[item.moduleKey] = []
        //         }
        //         files[item.moduleKey].push({
        //           name: item.fileName,
        //           url: item.fullFilePath,
        //           id: item.id,
        //           filePath: item.filePath
        //         })
        //       })
        //       this.psYjsFilesNow = files.dgAndYsPsYjs || [];
        //     }).catch(e => {
        //       this.$message.error(e.toString())
        //     })
        //   }).catch((e) => {
        //     this.$message.error(e.toString());
        //   });
        // }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getReviewList2 () {
      console.log('=============');

      this.$api.kjxm.review.projectExpertsInfoByReviewType({
        projectId: this.objId,
        reviewType: Number(this.reviewType) + 1,
      }).then(response => {
        this.data2 = response.data || [];
        this.psYjsFilesNow2 = [];
        // if(this.data2.length>0){
        //   this.$api.kjxm.review.getByTeamIdAndBusinessId(this.objId,this.data2[0].teamId).then(res => {
        //     getFiles(res.data.id).then((res) => {
        //       const files = {}
        //       res.data.forEach((item) => {
        //         if (!files[item.moduleKey]) {
        //           files[item.moduleKey] = []
        //         }
        //         files[item.moduleKey].push({
        //           name: item.fileName,
        //           url: item.fullFilePath,
        //           id: item.id,
        //           filePath: item.filePath
        //         })
        //       })
        //       this.psYjsFilesNow2 = files.dgAndYsPsYjs || [];
        //     }).catch(e => {
        //       this.$message.error(e.toString())
        //     })
        //   }).catch((e) => {
        //     this.$message.error(e.toString());
        //   });
        // }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
  }
}
</script>

<style scoped></style>
